<?php
error_reporting(E_WARNING);
include_once '../includes/metodos.php';
connectSql();
checkUser();

if(!empty($_POST['cmd']) && $_POST['cmd']== 'insert'){
	$cliente = mysql_query("SELECT * FROM tb_cliente WHERE nome='".$_POST['cliente']."'");
	$num_cli = mysql_num_rows($cliente);
	if($num_cli!=1){
		$query = "INSERT INTO tb_cliente VALUES ('', '".$_POST['cliente']."', '".$_POST['tel']."', '".$_POST['cel']."', NULL, NULL, NULL, NULL, NULL, NULL)";
		$sql = mysql_query($query);
	}
	$query = mysql_query("INSERT INTO tb_encaixe VALUES (NULL, ".$_POST['podo'].", NULL, '".$_POST['cliente']."', '".$_POST['data']."', '".$_POST['hora'].":00', 1, '".$_POST['tel']."', '".$_POST['cel']."')");
	if($query){
		echo '<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">location.href="index.php";</SCRIPT>';
	}else{
		die(mysql_error());
	}
}
include_once '../header.php';
?>
<body> 
<!-- Start: page-top-outer -->
<div id="page-top-outer">    
	<?php include_once '../menu.php';?>

<div id="page-heading"><h1>Encaixe</h1></div>

<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
<tr>
	<th rowspan="3" class="sized"><img src="images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
	<th class="topleft"></th>
	<td id="tbl-border-top">&nbsp;</td>
	<th class="topright"></th>
	<th rowspan="3" class="sized"><img src="images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
</tr>
<tr>
	<td id="tbl-border-left"></td>
	<td>
	<!--  start content-table-inner -->
	<div id="content-table-inner">
	
	<table border="0" width="100%" cellpadding="0" cellspacing="0">
	<tr valign="top">
	<td>
	
		<!--  start step-holder -->	
		<div id="step-holder">
			<div class="step-no-off">1</div>
			<div class="step-light-left"><a href="">Visualizar</a></div>
			<div class="step-dark-right">&nbsp;</div>
			<div class="step-no">2</div>
			<div class="step-dark-left">Marcar</div>
			<div class="step-dark-round">&nbsp;</div>
			<div class="clear"></div>
		</div>
	</td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0"  id="id-form">
		<form method="post" action="encaixe_new.php">
			<tr>
				<th valign="top">Cliente:</th>
				<td><input type="text" id="tags" class="inp-form" name="cliente" /></td>
			</tr>
			<tr>
				<th valign="top">Telefone:</th>
				<td><input type="text" class="inp-form" name="tel" /></td>
			</tr>
			<tr>
				<th valign="top">Celular:</th>
				<td><input type="text" class="inp-form" name="cel" /></td>
			</tr>
			<input type="hidden" name="cmd" value="insert"/>
			<input type="hidden" name="data" value="<?php echo $_POST['data'];?>"/>
			<input type="hidden" name="hora" value="<?php echo $_POST['hora'];?>"/>
			<input type="hidden" name="podo" value="<?php echo $_POST['podo'];?>"/>
			<td valign="top">
				<td><input class="form-submit" type="submit" value=""></td>
			</td>
		</form>
 </table>
<div class="clear"></div>

</div>
<!--  end content-table-inner  -->
</td>
<td id="tbl-border-right"></td>
</tr>
<tr>
	<th class="sized bottomleft"></th>
	<td id="tbl-border-bottom">&nbsp;</td>
	<th class="sized bottomright"></th>
</tr>
</table>

<div class="clear">&nbsp;</div>

</div>
<!--  end content -->
<div class="clear">&nbsp;</div>
</div>
<!--  end content-outer -->

<div class="clear">&nbsp;</div>
    
<?php include_once '../footer.php';?>
 
</body>
</html>